<div class="title">
  <div class='content'>
    预订项目
  </div>
  <% if being_edited %>
  <div class='tools'>
    <%= link_to '现货预订',
          new_spots_ordered_order_item_order_url(@order),
          :remote => true,
          :method => :get,
          :id => :add_order_item
    %>
    <%= link_to '厂家订做',
          new_order_made_order_item_order_url(@order),
          :remote => true,
          :method => :get,
          :id => :add_order_item
    %>
  </div>
  <% end %>
</div> 
<div class='info'>
  <div id='order_items' class='furnitures'>
    <table cellspacing='1' cellpadding='1'>
      <tr>
        <th>型号</th>
        <th>名称</th>
        <th>材质</th>
        <th>规格</th>
        <th>数量</th>
        <th>备注</th>
        <th>动态</th>
      </tr>
      <% @order.order_items.each do |item| %>      
      <tr id='item_<%= item.id %>' class='order_item <%= cycle '','hh', :name => 'furniture_item' %>'>
        <% if item.is_a?(OrderItem::SpotsOrdered) %>
        <td><%= item.furnitures.first.furniture_style.code %></td>
        <td><%= item.furnitures.first.furniture_style.name %></td>
        <td><%= item.furnitures.first.material.code %>-<%= item.furnitures.first.material.name %></td>
        <td><%= item.furnitures.each_with_object([]) { |furniture,specs| specs << furniture.spec }.join(',') %></td>
        <% else %>        
        <td><%= item.furniture.furniture_style.code %></td>
        <td><%= item.furniture.furniture_style.name %></td>
        <td><%= item.furniture.material.code %>-<%= item.furniture.material.name %></td>
        <td><%= item.furniture.spec %></td>
        <% end %>
        <td><%= item.ordered_count %></td>
        <td title='<%= item.remark %>'><%= truncate item.remark, :length => 20 %></td>
        <td width='80'>
          <%= t item.last_feed.code %>
        </td>
      </tr>
      <tr id='events_<%= item.id %>' class='item_events '>
        <td colspan='7'>
          <table class='events' cellspacing="1" cellpadding="1">
            <tr>
              <th></th>
              <th>描述</th>
              <th>
                <div class='recorder'>
                  登记人
                </div>                
                <div id='item_<%= item.id %>_tools' class='item_tools'>                  
                  <% if being_edited %>
                  <div>
                    <%= link_to "修改",
                          item.is_a?(OrderItem::SpotsOrdered) ? edit_spots_ordered_order_item_order_url(item) : edit_order_made_order_item_order_url(item),
                          :remote => true,
                          :method => :get                  
                     %>
                     <%= link_to "删除",
                          destroy_order_item_order_url(item),
                          :remote => true,
                          :method => :delete,
                          :id => "destroy_item_#{item.id}"    
                     %>
                     <script type="text/javascript" charset="utf-8">
                       $('#destroy_item_<%= item.id %>').bind('ajax:beforeSend', function () {
                         $('#events_<%= item.id %>').hide();
                         $('#item_<%= item.id %>').hide(1000);
                       })
                     </script>
                  </div>    
                  <% end %>                    
                </div>
              </th>                    
            </tr>
            <% item.feeds.each_with_index do |feed,index| %>
            <tr>
              <td width='40px'><%= index + 1 %>.</td>
              <td class='d'>
                <%= raw feed.short_desc %>
                <%= raw feed.remark.present? ? "<br/><b>备注：</b>#{raw(feed.remark) }" : '' %>
              </td>
              <td width='70px'>
                <%= @order.creator.full_name %>
              </td>                    
            </tr>
            <% end %>
            <!--
            <tr class='<%= cycle '','hh', :name => 'event' %>'>
              <td colspan='6'>
                <% if item.feeds.last.is_a?(Feed::OrderItemCreatedAndSpotsOrdered) %>
                <%= link_to_function '安装','$("#modal").show()', :class => :next_step %>
                <%= link_to_function '售后','$("#modal").show()', :class => :next_step %>
                <% end %>
              </td>
            </tr>
          -->
          </table>
        </td>
      </tr>    
      
      <script type="text/javascript" charset="utf-8">
       $('#item_<%= item.id %>').toggle(
          function() {
            $(this).addClass('h');
            $('#events_<%= item.id %>').show('slow');
          },
          function() {
            $(this).removeClass('h');
            $('#events_<%= item.id %>').hide();
          }
        );
      </script>
      <% end %>
      <% if @order.order_items.empty? %>
      <tr>
        <td class='c' colspan='7'>
          无记录
        </td>
      </tr>
      <% end %>
    </table>
  </div>
</div>        